package com.zhaohanlin.start;

import org.junit.Test;

/**
 * @author zhaohanlin
 */

public class InstanceOfTest {
    static class Fu {
        String name = "父类";

        public String info() {
            return "我是父类";
        }
    }

    static class Zi extends Fu {
        String name = "子类";

        @Override
        public String info() {
            return "我是子类";
        }

    }

    @Test
    public void instanceOf() {
        Fu ziA = new Zi();
        System.out.println(ziA.name);
        System.out.println(ziA.info());
        Fu ziB = new Zi();
        Zi ziC = new Zi();
        System.out.println(ziB instanceof Fu);
        System.out.println(ziB instanceof Zi);
        System.out.println(ziC instanceof Fu);
        System.out.println(ziC instanceof Zi);
        Zi ziD = new Zi();
        Fu fuB = ziD;
        System.out.println(fuB);
        Fu fuC = new Zi();
        Zi ziE = (Zi) fuC;
        System.out.println(ziE);
    }
}
